<?php

namespace App\Http\Controllers\Api\Miniprogram;

use App\Http\Controllers\Controller;
use App\Models\System\CheckItem;
use App\Models\System\GoodsCategory;

class CheckItemController extends Controller
{
    public function categories()
    {
        return $this->successJson(GoodsCategory::with(['icon'])->where('status', 1)->get());
    }

    public function getList()
    {
        $categoryId = request('goods_category_id', 1);
        return $this->successJson(CheckItem::with(['icon'])->where('status', 1)->where('goods_category_id', $categoryId)->orderBy('order')->get());
    }

    public function getDetail()
    {
        $id = request('id');
        $checkItem = CheckItem::with(['icon', 'banners', 'thumb', 'category'])->where('status', 1)->where('id', $id)->first();
        if (!$checkItem) {
            return $this->failJson('check_item_not_exist');
        }
        $checkItem->service_fee = round(env('DOOR_TO_DOOR_SERVICE', '200'), 2);
        $checkItem->price = round($checkItem->price, 1);
        $checkItem->service_price = round($checkItem->service_fee + $checkItem->price, 2);
        return $this->successJson($checkItem);
    }
}
